<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>社会保险登录系统(Servlet) ver 1.0</title>

<script type="text/javascript">

function ajaxValidate() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();//非IE
	} catch (e) {//异常时再判断使用的浏览器到底是不是IE
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");//IE
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}

	}
	return xmlHttp;
}

window.onload=function(){ 
	document.getElementById("user").value='ganhx';
	document.getElementById("password").value='ganhx';
	
	document.getElementById("checkname").onclick=function(){
		var username = document.getElementById("user").value;
		//1
		var xmlRequest = ajaxValidate();
		//2
		xmlRequest.onreadystatechange = function() {
			if (xmlRequest.readyState == 4) {
				if (xmlRequest.status == 200 || xmlRequest.staus == 304) {
					var java_data = xmlRequest.responseText;
					document.getElementById("divcheck").innerHTML = java_data;
				}
			}
		}
		/*
		*第二个代表的是servlet的名字，不是指的是对应目录位置
		*
		*/
		xmlRequest.open("post","checkUsernameAction",true);
		xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//4
		xmlRequest.send("user="+username);
	}
	
	
	document.getElementById("submit").onclick=function(){
		var username = document.getElementById("user").value;
		var password = document.getElementById("password").value;
		//1
		var xmlRequest = ajaxValidate();
		//2
		xmlRequest.onreadystatechange = function() {
			if (xmlRequest.readyState == 4) {
				if (xmlRequest.status == 200 || xmlRequest.staus == 304) {
					var java_data = xmlRequest.responseText;
					var obj_data = eval("("+java_data+")");
					alert("用户名:"+obj_data[0].user+"密码："+obj_data[0].password);
				}
			}
		}
		/*
		*第二个代表的是servlet的名字，不是指的是对应目录位置
		*
		*/
		xmlRequest.open("post",'com/pagemodel/login/Login',true);
		xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		//4
		xmlRequest.send("user="+username+"&password="+password);
	}
	
	
	}; 



function clearContent() {
	document.getElementById("user").value='';
	document.getElementById("password").value='';
}
</script>
  </head>
    
    <body>
	<div align="center" style="padding-top: 50px;">
		<form action="com/pagemodel/login/Login" method="post" enctype="application/x-www-form-urlencoded">
		<table  width="740" height="500" >
			<tr height="180">
				<td colspan="4"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%">用户名：</td>
				<td><input type="text" name="user" id="user"/></td>
				<td width="30%">
				<input type="button" name="checkname" id="checkname" value="检测"/>
				</td>
			</tr>
			
			<tr height="10">
			    <td>
				<div id="divcheck">
				</div>
				</td>
			</tr>
			
			<tr height="10">
				<td width="40%"></td>
				<td width="10%">密  码：</td>
				<td><input type="password" name="password" id="password" /></td>
				<td width="30%"></td>
			</tr>
			<tr height="10">
				<td width="40%"></td>
				<td width="10%"><input type="submit" value="登录" id="submit" name="submit"/></td>
				<td><input type="button" value="重置" onclick="clearContent()"/></td>
				<td width="30%"></td>
			</tr>
			<tr >
				<td></td>
			</tr>
		</table>
		</form>
	</div>
</body>
    
    
</html>
